﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace RiskMan.DataClass.Models.NotBasModels
{
    /// <summary>
    /// Модель данных для строки Ledders
    /// </summary>
    [Serializable]
    public class TradesOpen : INotifyPropertyChanged, ISerializable
    {
        #region private
        
        //заявки на открытие позиций
        private DateTime _openDate;
        private string _openOperation;
        private int _openQuantity;
        private int _openBalance;
        private string _openStatusOrder;
        private int _openID;
        private long _openNumberOrder;
        private double _openPriceOrder;

        //заявки на закрытие позиций
        private DateTime _closeDate;
        private string _closeOperation;
        private int _closeQuantity;
        private int _closeBalance;
        private string _closeStatusOrder;
        private int _closeID;
        private long _closeNumberOrder;
        private double _closePriceOrder;

       //заявки на закрытие позиций
        #endregion

        #region public
        /// <summary>
        /// Время заявки на открытие
        /// </summary>
        public DateTime OpenDate
        {
            get { return _openDate; }
            set
            {
                if (_openDate != value)
                {
                    _openDate = value;
                    RaisePropertyChanged("OpenDate");
                }
            }
        }
        /// <summary>
        /// Операция заявки на открытие позиции
        /// </summary>
        public string OpenOperation
        {
            get { return _openOperation; }
            set
            {
                if (_openOperation != value)
                {
                    _openOperation = value;
                    RaisePropertyChanged("OpenOperation");
                }
            }
        }
        /// <summary>
        /// Общее количество в заявке на открытие позиции
        /// </summary>
        public int OpenQuantity
        {
            get { return _openQuantity; }
            set
            {
                if (_openQuantity != value)
                {
                    _openQuantity = value;
                    RaisePropertyChanged("OpenQuantity");
                }
            }
        }
        /// <summary>
        /// Исполненное количество контрактов на открытие позиции
        /// </summary>
        public int OpenBalance
        {
            get { return _openBalance; }
            set
            {
                if (_openBalance != value)
                {
                    _openBalance = value;
                    RaisePropertyChanged("OpenBalance");
                }
            }
        }
        /// <summary>
        /// Статус заявки на открытие позиции
        /// </summary>
        public string OpenStatusOrder
        {
            get { return _openStatusOrder; }
            set
            {
                if (_openStatusOrder != value)
                {
                    _openStatusOrder = value;
                    RaisePropertyChanged("OpenStatusOrder");
                }
            }
        }
        /// <summary>
        /// ID заявки на открытие позиции
        /// </summary>
        public int OpenID
        {
            get { return _openID; }
            set
            {
                if (_openID != value)
                {
                    _openID = value;
                    RaisePropertyChanged("OpenID");
                }
            }
        }
        /// <summary>
        /// Номер заявки на открытие позиции
        /// </summary>
        public long OpenNumberOrder
        {
            get { return _openNumberOrder; }
            set
            {
                if (_openNumberOrder != value)
                {
                    _openNumberOrder = value;
                    RaisePropertyChanged("OpenNumberOrder");
                }
            }
        }
        /// <summary>
        /// Цена в заявке на открытие позиции
        /// </summary>
        public double OpenPriceOrder
        {
            get { return _openPriceOrder; }
            set
            {
                if (_openPriceOrder != value)
                {
                    _openPriceOrder = value;
                    RaisePropertyChanged("OpenPriceOrder");
                }
            }
        }

        /// <summary>
        /// Время заявки на закрытие
        /// </summary>
        public DateTime CloseDate
        {
            get { return _closeDate; }
            set
            {
                if (_closeDate != value)
                {
                    _closeDate = value;
                    RaisePropertyChanged("CloseDate");
                }
            }
        }
        /// <summary>
        /// Операция заявки на закрытие позиции
        /// </summary>
        public string CloseOperation
        {
            get { return _closeOperation; }
            set
            {
                if (_closeOperation != value)
                {
                    _closeOperation = value;
                    RaisePropertyChanged("CloseOperation");
                }
            }
        }
        /// <summary>
        /// Общее количество в заявке на закрытие позиции
        /// </summary>
        public int CloseQuantity
        {
            get { return _closeQuantity; }
            set
            {
                if (_closeQuantity != value)
                {
                    _closeQuantity = value;
                    RaisePropertyChanged("CloseQuantity");
                }
            }
        }
        /// <summary>
        /// Исполненное количество контрактов на закрытие позиции
        /// </summary>
        public int CloseBalance
        {
            get { return _closeBalance; }
            set
            {
                if (_closeBalance != value)
                {
                    _closeBalance = value;
                    RaisePropertyChanged("CloseBalance");
                }
            }
        }
        /// <summary>
        /// Статус заявки на закрытие позиции
        /// </summary>
        public string CloseStatusOrder
        {
            get { return _closeStatusOrder; }
            set
            {
                if (_closeStatusOrder != value)
                {
                    _closeStatusOrder = value;
                    RaisePropertyChanged("CloseStatusOrder");
                }
            }
        }
        /// <summary>
        /// ID заявки на закрытие позиции
        /// </summary>
        public int CloseID
        {
            get { return _closeID; }
            set
            {
                if (_closeID != value)
                {
                    _closeID = value;
                    RaisePropertyChanged("CloseID");
                }
            }
        }
        /// <summary>
        /// Номер заявки на закрытие позиции
        /// </summary>
        public long CloseNumberOrder
        {
            get { return _closeNumberOrder; }
            set
            {
                if (_closeNumberOrder != value)
                {
                    _closeNumberOrder = value;
                    RaisePropertyChanged("CloseNumberOrder");
                }
            }
        }
        /// <summary>
        /// Цена в заявке на закрытие позиции
        /// </summary>
        public double ClosePriceOrder
        {
            get { return _closePriceOrder; }
            set
            {
                if (_closePriceOrder != value)
                {
                    _closePriceOrder = value;
                    RaisePropertyChanged("ClosePriceOrder");
                }
            }
        }

        #endregion

        public TradesOpen() { }

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        public TradesOpen(SerializationInfo info, StreamingContext context)
        {
            OpenDate = info.GetDateTime ( "OpenDate" );
            OpenOperation = info.GetString( "OpenOperation" );
            OpenQuantity = info.GetInt32("OpenQuantity");
            OpenBalance = info.GetInt32("OpenBalance");
            OpenStatusOrder = info.GetString("OpenStatusOrder");
            OpenID = info.GetInt32("OpenID");
            OpenNumberOrder = info.GetInt64("OpenNumberOrder");
            OpenPriceOrder = info.GetDouble("OpenPriceOrder");

            CloseDate = info.GetDateTime("CloseDate");
            CloseOperation = info.GetString("CloseOperation");
            CloseQuantity = info.GetInt32("CloseQuantity");
            CloseBalance = info.GetInt32("CloseBalance");
            CloseStatusOrder = info.GetString("CloseStatusOrder");
            CloseID = info.GetInt32("CloseID");
            CloseNumberOrder = info.GetInt64("CloseNumberOrder");
            ClosePriceOrder = info.GetDouble("ClosePriceOrder");
        }

        public void GetObjectData ( SerializationInfo info, StreamingContext context )
        {
            info.AddValue("OpenDate", OpenDate);
            info.AddValue("OpenOperation", OpenOperation);
            info.AddValue("OpenQuantity", OpenQuantity);
            info.AddValue("OpenBalance", OpenBalance);
            info.AddValue("OpenStatusOrder", OpenStatusOrder);
            info.AddValue("OpenID", OpenID);
            info.AddValue("OpenNumberOrder", OpenNumberOrder);
            info.AddValue("OpenPriceOrder", OpenPriceOrder);

            info.AddValue("CloseDate", CloseDate);
            info.AddValue("CloseOperation", CloseOperation);
            info.AddValue("CloseQuantity", CloseQuantity);
            info.AddValue("CloseBalance", CloseBalance);
            info.AddValue("CloseStatusOrder", CloseStatusOrder);
            info.AddValue("CloseID", CloseID);
            info.AddValue("CloseNumberOrder", CloseNumberOrder);
            info.AddValue("ClosePriceOrder", ClosePriceOrder);
        }
    }
}
